//
//  ReactAgreementViewController.swift
//  Screen
//
//  Created by Season02 on 8/18/16.
//  Copyright © 2016 alex.chih. All rights reserved.
//

import React

var homeView : ReactHomePageViewController? = nil

class ReactHomePageViewController: UIViewController
{
    var rootView : RCTRootView? = nil
    
    override func viewDidLoad()
    {
        initReact()
        
        homeView = self
        
//        self.navigationController?.navigationController?.setToolbarHidden(true, animated: true)
//        self.navigationController?.setNavigationBarHidden(true, animated: true)
        
        UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent;
//        UIApplication.shared.setStatusBarStyle(UIStatusBarStyle.lightContent, animated: false)
        
    }
    
    fileprivate func initReact()
    {
        commonController = self
        let moduleName = "home"

//        let jsCodeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index.ios", fallbackResource: nil)
//        let jsCodeLocation = URL(string: "http://localhost:8081/index.ios.bundle?platform=ios")
        let jsCodeLocation = URL(string: Reference.ReactUrl("index.ios"))
        //        let jsCodeLocation = Bundle.main.url(forResource: "index.ios",  withExtension: "jsbundle")
        
        let mockData:NSDictionary = ["userId":"000111" , "controllerName":"AgreementPageLogic"]
//        et mockData:NSDictionary = ["userId":MGCSettingDone.getUserId() , "controllerName":"AgreementPageLogic"]
        
        let rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: moduleName, initialProperties: mockData as! [AnyHashable: Any] , launchOptions: nil)
//        rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: moduleName, initialProperties: nil , launchOptions: nil)
        
        let statusBarHeight = UIApplication.shared.statusBarFrame.height
//        rootView!.frame = CGRect(x: 0, y: statusBarHeight, width: self.view.bounds.width, height: self.view.bounds.height - statusBarHeight)
        rootView!.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height)
        
        self.view.addSubview(rootView!)
    }
    
    func popup()
    {
        DispatchQueue.global().async {
            DispatchQueue.main.async
                {
                    let _ = self.navigationController?.popViewController(animated: true);
                    self.navigationController?.setNavigationBarHidden(false, animated: true)
            }
        }
    }
    
}
